home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic new SourceCode and Projects / Audio Recorder 2.0 / frmAudioRecorder.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-02-18  |  13.9 KB  |  371 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form AudioRecorder 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "AudioRecorder"
  7.    ClientHeight    =   3765
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   7080
  11.    Icon            =   "frmAudioRecorder.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   3765
  15.    ScaleWidth      =   7080
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.CommandButton cmdSettings 
  18.       Caption         =   "Settings"
  19.       Height          =   495
  20.       Left            =   5970
  21.       TabIndex        =   10
  22.       ToolTipText     =   "Change rate, stereo/mono, 8/16 bits and program an automatic recording"
  23.       Top             =   120
  24.       Width           =   975
  25.    End
  26.    Begin MSComctlLib.Slider Slider1 
  27.       Height          =   375
  28.       Left            =   240
  29.       TabIndex        =   8
  30.       ToolTipText     =   "You can choose a beginning for playing the recording"
  31.       Top             =   960
  32.       Width           =   4575
  33.       _ExtentX        =   8070
  34.       _ExtentY        =   661
  35.       _Version        =   393216
  36.       LargeChange     =   500
  37.       SmallChange     =   100
  38.       TickStyle       =   3
  39.    End
  40.    Begin VB.CommandButton cmdWeb 
  41.       Caption         =   "Web"
  42.       Height          =   495
  43.       Left            =   4995
  44.       TabIndex        =   7
  45.       ToolTipText     =   "Visit the home page of me!! (Maybe a new version is available...)"
  46.       Top             =   120
  47.       Width           =   975
  48.    End
  49.    Begin VB.CommandButton cmdReset 
  50.       Caption         =   "Reset"
  51.       Height          =   495
  52.       Left            =   120
  53.       TabIndex        =   4
  54.       ToolTipText     =   "To start a new recording and adjusting all settings"
  55.       Top             =   120
  56.       Width           =   975
  57.    End
  58.    Begin VB.CommandButton cmdSave 
  59.       Caption         =   "Save"
  60.       Enabled         =   0   'False
  61.       Height          =   495
  62.       Left            =   4020
  63.       TabIndex        =   3
  64.       ToolTipText     =   "Save the recording as as WAV file"
  65.       Top             =   120
  66.       Width           =   975
  67.    End
  68.    Begin MSComDlg.CommonDialog CommonDialog1 
  69.       Left            =   5760
  70.       Top             =   2400
  71.       _ExtentX        =   847
  72.       _ExtentY        =   847
  73.       _Version        =   393216
  74.       FileName        =   " "
  75.       Orientation     =   2
  76.    End
  77.    Begin VB.CommandButton cmdPlay 
  78.       Caption         =   "Play"
  79.       Enabled         =   0   'False
  80.       Height          =   495
  81.       Left            =   3045
  82.       TabIndex        =   2
  83.       ToolTipText     =   "Play the recording"
  84.       Top             =   120
  85.       Width           =   975
  86.    End
  87.    Begin VB.CommandButton cmdStop 
  88.       Caption         =   "Stop"
  89.       Enabled         =   0   'False
  90.       Height          =   495
  91.       Left            =   2070
  92.       TabIndex        =   1
  93.       ToolTipText     =   "Stop recording or playing"
  94.       Top             =   120
  95.       Width           =   975
  96.    End
  97.    Begin VB.CommandButton cmdRecord 
  98.       Caption         =   "Record"
  99.       Height          =   495
  100.       Left            =   1095
  101.       TabIndex        =   0
  102.       ToolTipText     =   "Start recording immediate"
  103.       Top             =   120
  104.       Width           =   975
  105.    End
  106.    Begin VB.Frame Frame5 
  107.       Caption         =   "Starting position for play (in milliseconds)"
  108.       Height          =   855
  109.       Left            =   120
  110.       TabIndex        =   9
  111.       Top             =   720
  112.       Width           =   4815
  113.    End
  114.    Begin VB.Timer Timer2 
  115.       Interval        =   200
  116.       Left            =   5160
  117.       Top             =   2400
  118.    End
  119.    Begin VB.Frame Frame4 
  120.       Caption         =   "Statistics"
  121.       Height          =   1815
  122.       Left            =   120
  123.       TabIndex        =   5
  124.       Top             =   1680
  125.       Width           =   4815
  126.       Begin VB.Label StatisticsLabel 
  127.          BackColor       =   &H00000000&
  128.          Caption         =   " "
  129.          ForeColor       =   &H0000FF00&
  130.          Height          =   1455
  131.          Left            =   120
  132.          TabIndex        =   6
  133.          ToolTipText     =   "Information about the recording"
  134.          Top             =   240
  135.          Width           =   4575
  136.       End
  137.    End
  138. Attribute VB_Name = "AudioRecorder"
  139. Attribute VB_GlobalNameSpace = False
  140. Attribute VB_Creatable = False
  141. Attribute VB_PredeclaredId = True
  142. Attribute VB_Exposed = False
  143. Option Explicit
  144. 'Copyright: E. de Vries
  145. 'e-mail: eeltje@geocities.com
  146. 'This code can be used as freeware
  147. Const AppName = "AudioRecorder"
  148. Private Sub cmdSave_Click()
  149.     Dim sName As String
  150.     If WaveMidiFileName = "" Then
  151.         sName = "Radio_from_" & CStr(WaveRecordingStartTime) & "_to_" & CStr(WaveRecordingStopTime)
  152.         sName = Replace(sName, ":", "-")
  153.         sName = Replace(sName, " ", "_")
  154.         sName = Replace(sName, "/", "-")
  155.     Else
  156.         sName = WaveMidiFileName
  157.         sName = Replace(sName, "MID", "wav")
  158.     End If
  159.     CommonDialog1.FileName = sName
  160.     CommonDialog1.CancelError = True
  161.     On Error GoTo ErrHandler1
  162.     CommonDialog1.Filter = "WAV file (*.wav*)|*.wav"
  163.     CommonDialog1.Flags = &H2 Or &H400
  164.     CommonDialog1.ShowSave
  165.     sName = CommonDialog1.FileName
  166.     WaveSaveAs (sName)
  167.     Exit Sub
  168. ErrHandler1:
  169. End Sub
  170. Private Sub cmdRecord_Click()
  171.     Dim settings As String
  172.     Dim Alignment As Integer
  173.       
  174.     Alignment = Channels * Resolution / 8
  175.     settings = "set capture alignment " & CStr(Alignment) & " bitspersample " & CStr(Resolution) & " samplespersec " & CStr(Rate) & " channels " & CStr(Channels) & " bytespersec " & CStr(Alignment * Rate)
  176.     WaveReset
  177.     WaveSet
  178.     WaveRecord
  179.     WaveRecordingStartTime = Now
  180.     cmdStop.Enabled = True   'Enable the STOP BUTTON
  181.     cmdPlay.Enabled = False  'Disable the "PLAY" button
  182.     cmdSave.Enabled = False  'Disable the "SAVE AS" button
  183.     cmdRecord.Enabled = False 'Disable the "RECORD" button
  184. End Sub
  185. Private Sub cmdSettings_Click()
  186. Dim strWhat As String
  187.     ' show the user entry form modally
  188.     strWhat = MsgBox("If you continue your data will be lost!", vbOKCancel)
  189.     If strWhat = vbCancel Then
  190.         Exit Sub
  191.     End If
  192.     Slider1.Max = 10
  193.     Slider1.Value = 0
  194.     Slider1.Refresh
  195.     cmdRecord.Enabled = True
  196.     cmdStop.Enabled = False
  197.     cmdPlay.Enabled = False
  198.     cmdSave.Enabled = False
  199.     WaveReset
  200.     Rate = CLng(GetSetting("AudioRecorder", "StartUp", "Rate", "110025"))
  201.     Channels = CInt(GetSetting("AudioRecorder", "StartUp", "Channels", "1"))
  202.     Resolution = CInt(GetSetting("AudioRecorder", "StartUp", "Resolution", "16"))
  203.     WaveFileName = GetSetting("AudioRecorder", "StartUp", "WaveFileName", "C:\Radio.wav")
  204.     WaveAutomaticSave = GetSetting("AudioRecorder", "StartUp", "WaveAutomaticSave", "True")
  205.     WaveRecordingImmediate = True
  206.     WaveRecordingReady = False
  207.     WaveRecording = False
  208.     WavePlaying = False
  209.     'Be sure to change the Value property of the appropriate button!!
  210.     'if you change the default values!
  211.     WaveSet
  212.     frmSettings.optRecordImmediate.Value = True
  213.     frmSettings.Show vbModal
  214. End Sub
  215. Private Sub cmdStop_Click()
  216.     WaveStop
  217.     cmdSave.Enabled = True  'Enable the "SAVE AS" button
  218.     cmdPlay.Enabled = True  'Enable the "PLAY" button
  219.     cmdStop.Enabled = False 'Disable the "STOP" button
  220.     If WavePosition = 0 Then
  221.         Slider1.Max = 10
  222.     Else
  223.         If WaveRecordingImmediate And (Not WavePlaying) Then Slider1.Max = WavePosition
  224.         If (Not WaveRecordingImmediate) And WaveRecording Then Slider1.Max = WavePosition
  225.     End If
  226.     If WaveRecording Then WaveRecordingReady = True
  227.     WaveRecordingStopTime = Now
  228.     WaveRecording = False
  229.     WavePlaying = False
  230.     frmSettings.optRecordProgrammed.Value = False
  231.     frmSettings.optRecordImmediate.Value = True
  232.     frmSettings.lblTimes.Visible = False
  233. End Sub
  234. Private Sub cmdPlay_Click()
  235.     WavePlayFrom (Slider1.Value)
  236.     WavePlaying = True
  237.     cmdStop.Enabled = True
  238.     cmdPlay.Enabled = False
  239. End Sub
  240. Private Sub cmdWeb_Click()
  241.   Dim ret&
  242.   ret& = ShellExecute(Me.hwnd, "Open", "http://home.wxs.nl/~eeltjevr/", "", App.Path, 1)
  243. End Sub
  244. Private Sub cmdReset_Click()
  245.     Slider1.Max = 10
  246.     Slider1.Value = 0
  247.     Slider1.Refresh
  248.     cmdRecord.Enabled = True
  249.     cmdStop.Enabled = False
  250.     cmdPlay.Enabled = False
  251.     cmdSave.Enabled = False
  252.     WaveReset
  253.     Rate = CLng(GetSetting("AudioRecorder", "StartUp", "Rate", "110025"))
  254.     Channels = CInt(GetSetting("AudioRecorder", "StartUp", "Channels", "1"))
  255.     Resolution = CInt(GetSetting("AudioRecorder", "StartUp", "Resolution", "16"))
  256.     WaveFileName = GetSetting("AudioRecorder", "StartUp", "WaveFileName", "C:\Radio.wav")
  257.     WaveAutomaticSave = GetSetting("AudioRecorder", "StartUp", "WaveAutomaticSave", "True")
  258.     WaveRecordingImmediate = True
  259.     WaveRecordingReady = False
  260.     WaveRecording = False
  261.     WavePlaying = False
  262.     WaveMidiFileName = ""
  263.     'Be sure to change the Value property of the appropriate button!!
  264.     'if you change the default values!
  265.     WaveSet
  266.     If WaveRenameNecessary Then
  267.         Name WaveShortFileName As WaveLongFileName
  268.         WaveRenameNecessary = False
  269.         WaveShortFileName = ""
  270.     End If
  271. End Sub
  272. Private Sub Form_Load()
  273.     WaveReset
  274.     Rate = CLng(GetSetting("AudioRecorder", "StartUp", "Rate", "110025"))
  275.     Channels = CInt(GetSetting("AudioRecorder", "StartUp", "Channels", "1"))
  276.     Resolution = CInt(GetSetting("AudioRecorder", "StartUp", "Resolution", "16"))
  277.     WaveFileName = GetSetting("AudioRecorder", "StartUp", "WaveFileName", "C:\Radio.wav")
  278.     WaveAutomaticSave = GetSetting("AudioRecorder", "StartUp", "WaveAutomaticSave", "True")
  279.     WaveRecordingImmediate = True
  280.     WaveRecordingReady = False
  281.     WaveRecording = False
  282.     WavePlaying = False
  283.     'Be sure to change the Value property of the appropriate button!!
  284.     'if you change the default values!
  285.     WaveSet
  286.     WaveRecordingStartTime = Now + TimeSerial(0, 15, 0)
  287.     WaveRecordingStopTime = WaveRecordingStartTime + TimeSerial(0, 15, 0)
  288.     WaveMidiFileName = ""
  289.     WaveRenameNecessary = False
  290. End Sub
  291. Private Sub Form_Unload(Cancel As Integer)
  292.     WaveClose
  293.     Call SaveSetting("AudioRecorder", "StartUp", "Rate", CStr(Rate))
  294.     Call SaveSetting("AudioRecorder", "StartUp", "Channels", CStr(Channels))
  295.     Call SaveSetting("AudioRecorder", "StartUp", "Resolution", CStr(Resolution))
  296.     Call SaveSetting("AudioRecorder", "StartUp", "WaveFileName", WaveFileName)
  297.     Call SaveSetting("AudioRecorder", "StartUp", "WaveAutomaticSave", CStr(WaveAutomaticSave))
  298.     If WaveRenameNecessary Then
  299.         Name WaveShortFileName As WaveLongFileName
  300.         WaveRenameNecessary = False
  301.         WaveShortFileName = ""
  302.     End If
  303.     End
  304. End Sub
  305. Private Sub Timer2_Timer()
  306.     Dim RecordingTimes As String
  307.     Dim msg As String
  308.     RecordingTimes = "Start time:  " & WaveRecordingStartTime & vbCrLf _
  309.                     & "Stop time:  " & WaveRecordingStopTime
  310.     WaveStatistics
  311.     If Not WaveRecordingImmediate Then
  312.         WaveStatisticsMsg = WaveStatisticsMsg & "Programmed recording"
  313.         If WaveAutomaticSave Then
  314.             WaveStatisticsMsg = WaveStatisticsMsg & " (automatic save)"
  315.         Else
  316.             WaveStatisticsMsg = WaveStatisticsMsg & " (manual save)"
  317.         End If
  318.         WaveStatisticsMsg = WaveStatisticsMsg & vbCrLf & vbCrLf & RecordingTimes
  319.     End If
  320.     StatisticsLabel.Caption = WaveStatisticsMsg
  321.     WaveStatus
  322.     If WaveStatusMsg <> AudioRecorder.Caption Then AudioRecorder.Caption = WaveStatusMsg
  323.     If InStr(AudioRecorder.Caption, "stopped") > 0 Then
  324.         cmdStop.Enabled = False
  325.         cmdPlay.Enabled = True
  326.     End If
  327.     If RecordingTimes <> frmSettings.lblTimes.Caption Then frmSettings.lblTimes.Caption = RecordingTimes
  328.     If (Now > WaveRecordingStartTime) _
  329.             And (Not WaveRecordingReady) _
  330.             And (Not WaveRecordingImmediate) _
  331.             And (Not WaveRecording) Then
  332.         WaveReset
  333.         WaveSet
  334.         WaveRecord
  335.         WaveRecording = True
  336.         cmdStop.Enabled = True   'Enable the STOP BUTTON
  337.         cmdPlay.Enabled = False  'Disable the "PLAY" button
  338.         cmdSave.Enabled = False  'Disable the "SAVE AS" button
  339.         cmdRecord.Enabled = False 'Disable the "RECORD" button
  340.     End If
  341.     If (Now > WaveRecordingStopTime) And (Not WaveRecordingReady) And (Not WaveRecordingImmediate) Then
  342.         WaveStop
  343.         cmdSave.Enabled = True 'Enable the "SAVE AS" button
  344.         cmdPlay.Enabled = True 'Enable the "PLAY" button
  345.         cmdStop.Enabled = False 'Disable the "STOP" button
  346.         If WavePosition > 0 Then
  347.             Slider1.Max = WavePosition
  348.         Else
  349.             Slider1.Max = 10
  350.         End If
  351.         WaveRecording = False
  352.         WaveRecordingReady = True
  353.         If WaveAutomaticSave Then
  354.             WaveFileName = "Radio_from_" & CStr(WaveRecordingStartTime) & "_to_" & CStr(WaveRecordingStopTime)
  355.             WaveFileName = Replace(WaveFileName, ":", ".")
  356.             WaveFileName = Replace(WaveFileName, " ", "_")
  357.             WaveFileName = WaveFileName & ".wav"
  358.             WaveSaveAs (WaveFileName)
  359.             msg = "Recording has been saved" & vbCrLf
  360.             msg = msg & "Filename: " & WaveFileName
  361.             MsgBox (msg)
  362.         Else
  363.             msg = "Recording is ready" & vbCrLf
  364.             msg = msg & "Don't forget to save recording..."
  365.             MsgBox (msg)
  366.         End If
  367.         frmSettings.optRecordProgrammed.Value = False
  368.         frmSettings.optRecordImmediate.Value = True
  369.     End If
  370. End Sub
  371.